test(@modelcontextprotocol/node): cover pre-read body pattern in stateless mode#2026
Open
Zelys-DFKH wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
test(@modelcontextprotocol/node): cover pre-read body pattern in stateless mode#2026Zelys-DFKH wants to merge 1 commit intomodelcontextprotocol:mainfrom
Zelys-DFKH wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
…eless mode Add a test for the handleRequest(req, res, parsedBody) overload in stateless mode: drain the IncomingMessage body upstream (body-parser pattern), pass it as parsedBody, and verify that both an initialize request and a subsequent tools/list request succeed on the same reused transport. Found while investigating modelcontextprotocol#1994. In v2 the _hasHandledRequest reuse restriction was removed, so both requests succeed. This test pins that. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1994 (partial; #1995 handles the v1.x production fix)
The
handleRequest(req, res, parsedBody)overload exists for body-parser users: drain the stream first, then pass the parsed body. It's documented in the JSDoc with an Express example. The stateless describe block had no test covering that pattern, so it was possible to break it without anyone noticing.This adds one. An initialize request followed by a
tools/listrequest, both with the body pre-read viafor awaitand handed off asparsedBody. The second request is what was missing.I found this while digging into #1994. The v1.x issue was a real bug (
_hasHandledRequestthrew on the second request and produced an opaque 500). In v2 that restriction was removed entirely, so both requests succeed fine. This test makes sure it stays that way.Test plan